package arts.spbu.testswing;

/**
 * Created with IntelliJ IDEA.
 * User: pev67021
 * Date: 07.11.12
 * Time: 11:39
 */
public class IntervalBorder implements Comparable {

    private int pos;
    private boolean left;
    private int pair_id;

    public IntervalBorder(int pos, boolean left, int pair_id) {
        this.pos = pos;
        this.left = left;
        this.pair_id = pair_id;
    }

    public int getPos() {
        return this.pos;
    }

    public boolean isLeft() {
        return this.left;
    }

    public int getPairID() {
        return this.pair_id;
    }

    @Override
    public int compareTo(Object other) {
        if (!(other instanceof IntervalBorder)){
            throw new ClassCastException("Not a valid object!");
        }
        IntervalBorder tempborder = (IntervalBorder)other;

        if (tempborder.getPos() < this.pos)
            return 1;
        if (tempborder.getPos() > this.pos)
            return -1;
        if (tempborder.isLeft() && (!this.left))
            return 1;
        if ((!tempborder.isLeft()) && this.left)
            return -1;
        if (tempborder.getPairID() < this.pair_id)
            return 1;
        if (tempborder.getPairID() > this.pair_id)
            return -1;

        return 0;
    }

    @Override
    public String toString(){
        if (this.left)
            return this.pos + "-left-" + this.pair_id;
        else
            return this.pos + "-right-" + this.pair_id;
    }

}
